package com.gdut.huayan.config;

import com.gdut.huayan.service.job.WechatAccessTokenJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    private static final String JOB_GROUP_NAME = "PJB_JOBGROUP_NAME";
    private static final String TRIGGER_GROUP_NAME = "PJB_TRIGGERGROUP_NAME";

    @Bean
    public JobDetail getAccessTokenJobDetail() {
        return JobBuilder.newJob(WechatAccessTokenJob.class)
                .withIdentity("getAccessToken", JOB_GROUP_NAME)
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger getAccessTokenTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0/30 * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(getAccessTokenJobDetail())
                .withIdentity("getAccessToken", TRIGGER_GROUP_NAME)
                .withSchedule(cronScheduleBuilder)
                .build();
    }

}
